package com.lagou.module3_6;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * @author wsl
 * @date 2021/7/21 22:09
 * @project_name javase
 */
public class WorkerListTest {

    public static void main(String[] args) {

        //1.声明一个Worker类型的引用指向该类型的对象
         Worker w1 = new Worker();
         w1.setName("凤姐");
         w1.work();

        System.out.println("-----------------------------------------------------");
         //2.定义List集合，在List集合中增加三个员工
        List<Worker> lt1 = new LinkedList<>();
        lt1.add(new Worker("凤姐",18,20000));
        lt1.add(new Worker("欧阳锋",60,8000));
        lt1.add(new Worker("刘德华",40,30000));
        System.out.println("lt1= "+lt1);//凤姐 欧阳锋 刘德华

        System.out.println("-----------------------------------------------------");
        //3.在"欧阳峰"之前插入一个员工，信息为：姓名："张柏芝"，年龄：35，工资3300
        lt1.add(1,new Worker("张柏芝",35,3300));
        System.out.println("lt1= "+lt1);//凤姐 张柏芝 欧阳锋 刘德华

        System.out.println("-----------------------------------------------------");
        //4.删除"刘德华"的信息
        lt1.remove(lt1.size()-1);
        System.out.println("lt1= "+lt1);//凤姐 张柏芝 欧阳锋

        System.out.println("-----------------------------------------------------");
        //5.利用for 循环遍历，打印List 中所有员工的信息
        for(Worker w2:lt1){
            System.out.println("w2= "+w2);
        }

        System.out.println("-----------------------------------------------------");
        //6.利用迭代遍历，对List 中所有的员工调用work 方法
        Iterator<Worker> iterator = lt1.iterator();
        while (iterator.hasNext()){
            iterator.next().work();
        }

        System.out.println("-----------------------------------------------------");
        //7.为Worker类重写equals 方法，当姓名、年龄、工资全部相等时候才返回true
        Worker w3 = new Worker("欧阳锋", 60, 8000);
        for (int i = 0; i < lt1.size(); i++){
            System.out.println(lt1.get(i)+"="+w3.equals(lt1.get(i)));//false false true
        }
    }
}

